Rearranging Equation (3), the following equation (Eq. 5) is obtained. It can be seen that the pixel variance within the box can also be obtained during the same pass as when calculating the mean. This is achieved by accumulating the square of the intensity values while accumulating original pixel values for mean calculation. The variance of points within the box is calculated using Equation (5).
Therefore we have a fast way to obtain the mean and variance of the input images for the calculation of the cross-correlation that is to be used as a measure of similarity between matching candidates from the left and right images.