unmerged changes from 2.4 branch

This changes weren't merged from 2.4 branch into master.

For https://github.com/Itseez/opencv/pull/625