Please see the following blog post for more details about this code
Image Alignment (ECC) in OpenCV ( C++ / Python )