see https://github.com/Itseez/opencv/pull/3137 (cherry picked from commit ebe36d6e7c99430b16f61e6b2ee832b91f155ff7)