The production of charm and beauty quarks in ep interactions has been measured with the ZEUS detector at HERA for squared four-momentum exchange Q(2) > 20 GeV2, using an integrated luminosity of 126 pb(-1). Charm and beauty quarks were identified through their decays into muons. Differential cross sections were measured for muon transverse momenta p(T)(mu) > 1.5 GeV and pseudorapidities - 1.6 < eta(mu) < 2.3, as a function of p(T)(mu), eta(mu), Q(2) and Bjorken x. The charm and beauty contributions to the proton structure function F-2 were also extracted. The results agree with previous measurements based on independent techniques and are well described by QCD predictions.