Can I subtract the current image from a previous one inside a material?

I am trying to create an effect that essentially involves the following operation: If I have an image at time instant t, I want to compute the difference between that image and the same image at time instant (t-1). Thus, all the pixels whose values have changed (due to movement or lighting changes) will ‘light up’.

Is it possible to perform this inside a material? I have seen some examples of how optical flow is being computed inside material nodes as a postprocess effect which seem somewhat relevant, but for my case, I’m more interested in pixel intensities than velocity. Is there anyway to keep track of the image rendered from the previous frame?