Invariant polytopes of sets of matrices with application to regularity of wavelets and subdivisions