Are you assuming they're aligned, or are you using the MSE to try and align them? (There are better ways to align images, but MSE is a conceptually simple one.)

If the former, then pseudocode...