Bug 1523

Fix suggested by Jukka Holappa who investigated the problem
http://code.opencv.org/issues/1523