When the camera is stationary, then it is easy to detect the movement simply by subtracting the previous frame of the current frame, using optical flow:
OpenCV v2.4.9.0: Motion Analysis and Object Tracking
OpenCV v3.0: Motion Analysis and Object Tracking
But how to detect the moving objects during our own motion? When camera is moving, any difference (subtracting) between previous and current frames will give to us movements of background.
Moreover, the foreground (poles, trees) will move faster than the background (sky). If we look at everything that deviates from the average value of the motion, we find these poles and trees, but they are actually stationary.
How to detect any motions of other objects, when our camera is moving?