This is not my work, I simply translated the code into Python.
It takes two frame and calculates the velocity vector in x and y direction.
Applies Gaussian derivative mask in x axis and y axis to the frame 1 and 2. This attains Ix and Iy.
For It you just apply a normal Gaussian kernel and subtract the two frames.
Ix(qi) = Ix
so on and so on
Then use this equation to calculate Vx and Vy:
And here is the Image: