backport a function from trunk

This is just a backport from trunk of a function I added months ago (I need it to continue libmv development on 2.4)