Avoid duplicating code in the MotionEstimate test

All the tests of the line search (unoptimized and optimized)
use the exact same copypasted structure. Instead factorize this
into a test function which uses the provided function.
Merge pull request #788 from mstorsjo/factorize-duplicated-test

Avoid duplicating code in the MotionEstimate test

Approved by Sijia.