We consider an intermediary's problem of dynamically matching demand and supply of heterogeneous types in a periodic-review fashion. More specifically, there are two disjoint sets of demand and supply types. There is a reward associated with each possible matching of a demand type and a supply type. In each period, demand and supply of various types arrive in random quantities. The platform's problem is to decide on the optimal matching policy to maximize the total discounted rewards minus costs, given that unmatched demand and supply will incur waiting or holding costs, and will be carried over to the next period with abandonments. This problem applies to many emerging settings in the sharing economy and also includes many classic problems, e.g., assignment/transportation problems, as special cases. For this dynamic matching problem, we provide sufficient and robustly necessary conditions (which we call modified Monge conditions) only on matching rewards such that the optimal matching policy follows a priority hierarchy among possible matching pairs: if some pair of demand and supply types is not matched as much as possible, all pairs that have strictly lower priority down the hierarchy should not be matched. The modified Monge condition generalizes the Monge sequence condition, discovered by Gaspard Monge in 1781, that guarantees a static and balanced transportation problem to be solved by a greedy algorithm. We show the modified Monge conditions are satisfied by vertically and unidirectionally horizontally differentiated types, for which quality and distance determine priority, respectively. As a result of the priority property, the optimal matching policy boils down to a match-down-to threshold structure (instead of matching as much as possible in the greedy algorithm) when considering a specific pair of demand and supply types, along the priority hierarchy.