test + fix for bug 3172

fix and regression test for bug 3172 (http://code.opencv.org/issues/3172)