Is It necessary, in the standard model, that the number of quark generations equals the number of lepton generations, i.e. 3? This question showed up in my particle physics exam and I'm not sure of the answer. I said no, since I can't see any reason why they must be equal.
But I my answer is right, I find it odd that it's just a coincidence that they're both 3.
 A: Honest answer for your question is ''No''! As in the standard model (SM), the number of fermion generations appears as an arbitrary parameter, meaning that a mathematically consistent theory can be built up using any number of fermion generations. Therefore, In order to answer the question perhaps we may need to beyond the standard model. 
In the quest for such a model(s), first lets rephrase your question is the following way: 

Is there any extension of the standard model be possible where the
  number of fermion generations can in any way be explained through the
  internal consistency of the model? (since we don't have the answer within the framework of SM.)

Its good to  start from SM itself. Lets go back in sixties. If we make a table of fermions, those were discovered up to 1965, it would looks like:
\begin{eqnarray}
\text{Lepton}& : & \begin{pmatrix} \nu_{e}\\ e \end{pmatrix},\quad \begin{pmatrix} \nu_{\mu}\\ \mu\end{pmatrix} \\
\text{Quark} & : & \begin{pmatrix} u \\ d \end{pmatrix},\qquad s
\end{eqnarray}
Anyone with naked eye can say how ''ugly'' this table is looks like! In fact it was   James Bjorken
and Sheldon Glashow
proposed the existance of chram ($c$) quark in order to restore the ''quark-lepton symmetry''. The table now looks more symmetric and beautiful:
\begin{eqnarray}
\text{Lepton}& : & \begin{pmatrix} \nu_{e}\\ e \end{pmatrix},\quad \begin{pmatrix} \nu_{\mu}\\ \mu\end{pmatrix} \\
\text{Quark} & : & \begin{pmatrix} u \\ d \end{pmatrix},\qquad \begin{pmatrix} c \\ s \end{pmatrix}
\end{eqnarray}
Which was later discovered during November Revolution 1974 . 
Lesson is, these two physicists were dictated by the notion of symmetry in order to restore the order in the realm of fermions. Later GIM mechanism was given an explanation of the non-existent of FCNC in SM taking into account the charm quark.
The very existence of three generations of quarks is necessary for CP violation. And also for anomaly cancellations to make the SM mathematically consistant.
But the undeylying symmetry (if it really exists) which may ensure the equal numbers of quarks and leptons, yet to be discovered. 
Story that goes beyond SM:
Back in nineties an extension of SM was proposed by F. Pisano here and V. Pleitez based on gauge group $SU(3)_{L}\times U(1)_{Y}$. Their model to accommodate the standard fermions into multiplets of this gauge group which must include some new fermions. 
This model has remarkable feature. As we already know that, a consistent quantum field theory must be free from gauge anomaly. Without that, theory become ill. In case of SM the anomalies get cancelled in miraculous (or should we say in an ugly way?) way. But for the model with gauge group $SU(3)_{c}\times SU(3)_{L}\times U(1)_{Y}$, has the interesting feature
that each generation of fermions is anomalous, but that with three generations the anomalies cancelled. 
In other words,

Electroweak interactions based on a gauge group $SU(3)_{L}\times U(1)_{Y}$, coupled to to the QCD gauge group $SU(3)_{c}$ can predict
  the number of generations to be multiples of three.

(For technical detail one can read this paper). But with the cost that we have to incorporate a right handed neutrino in the game. In fact, one may find other different models with the same features.
GUT considerations: In a recent paper Pritibhajan Byakti et al proposed a grand unified theory based on the gauge group $SU(9)$. The model uses fermions in antisymmetric representations only and the consistency of the model demands that the number of fermion generations is three. Nevertheless like all GUT, it also come up with some superheavy gauge bosons. Which can trigger baryon number non-conserving processes.
The upshot is, perhaps we would be able to explain the lepton-quark symmetry with the price of some new physics (may be new particles) which lives beyond the SM.
A: 
This question showed up in my particle physics exam and I'm not sure of the answer. I said no, since I can't see any reason why they must be equal. 

There are no conserved quantities between the lepton and quark generations (for example there is no rule such as a top quark can only decay into a tau lepton or something), so there is no actual reason why there need to be three generations of quarks and three generations of leptons within the current standard model.

But I my answer is right, I find it odd that it's just a coincidence that they're both 3.

It probably is not a coincidence, but a consequence of some underlying undiscovered symmetry. However, there is no current human physics law which requires the same number of quark and lepton generations.
A: We don't know why they balance in number,  as humans we like symmetry and balance, but whether nature likes them as much as us,  we don't know. It might be a coincidence ( it's probably not), but again we could discover something  tomorrow that "distorts" the system.
It seems necessary that there are 3 of each for our current standard model of understanding forces to work, but that could change at any time, or not for a long time. 

A more detailed, interesting and much better informed  similar question is Quarks and Leptons 
