title: CV2 optical flow function is not deterministic
body: <p>I'm trying to get the amount of motion by calculating the optical flow magnitude between two images (in Python 3.7 and <code>cv2</code> v4.0). But passing the same images, I see the final value is not deterministic. Sometimes it prints <code>inf</code> and sometimes it prints <code>7.372749678324908e-05</code>.</p>
  <p>What is the problem? Why it's not deterministic?!</p>
  <pre><code>def getOpticalMag(prev_image, curr_image):
  
      prev_image_gray = cv2.cvtColor(prev_image, cv2.COLOR_BGR2GRAY)
      curr_image_gray = cv2.cvtColor(curr_image, cv2.COLOR_BGR2GRAY)
  
      flow = cv2.calcOpticalFlowFarneback(prev_image_gray, curr_image_gray, flow=None,
                                          pyr_scale=0.5, levels=1, winsize=15,
                                          iterations=2,
                                          poly_n=5, poly_sigma=1.1, flags=0)
  
      mag, ang = cv2.cartToPolar(flow[...,0], flow[...,1])
  
      return np.mean(mag)
  </code></pre>