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.