Fix for bug #3219 (undefined reference in GPU samples)

Original PR (https://github.com/Itseez/opencv/pull/1267) was merged into master branch, but the fix is also applicable to 2.4 branch.