Let \( x \) years ago, the ratio of their ages was \( 3 : 5 \).
So,
\[
\frac{40 - x}{60 - x} = \frac{3}{5}
\]
Cross-multiply:
\[
5(40 - x) = 3(60 - x)
\]
\[
200 - 5x = 180 - 3x
\]
\[
200 - 180 = 5x - 3x
\]
\[
20 = 2x \quad \Rightarrow \quad x = 10
\]
Thus, the ratio of their ages was \( 3 : 5 \) 10 years ago.