fix installation of main module headers

see: http://code.opencv.org/issues/2897

The order of the 2 conditions is really important, as every ```MATCHES``` operator sets ```${CMAKE_MATCH_1}```, which is needed inside the condition block.
Ideally, this should be done using a single regex with a negative forward lookahead, but CMake doesn't seem to support this...