By Section 8.3.1 of the book: A primer on mapping class groups by Farb and Margalit, a pair of pants is a compact surface of genus 0 with three boundary components. Let $S$ be a compact surface with $\chi(S)<0$. A pair of pants decomposition of $S$, or a pants decomposition of $S$, is a collection of disjoint simple closed curves in $S$ with the property that when we cut $S$ along these curves, we obtain a disjoint union of pairs of pants. Equivalently, a pants decomposition of $S$ is a maximal collection of disjoint, essential simple closed curves in $S$ with the property that no two of these curves are isotopic. In particular, a pants decomposition of $\Sigma_g$ (the orientable closed surface of genus $g$) for $g>1$ has $3g-3$ curves, cutting $\Sigma_g$ into $2g-2$ pairs of pants.
On the other hand, according to Riemann's computation, the dimension of the moduli space $\mathcal{M}_g$ of algebraic curves of genus $g>1$ is $3g-3$. See, for example, the book: Algebraic curves towards moduli spaces.
My question: why are the number of curves in the pants decomposition of $\Sigma_g$ for $g>1$ and the dimension of the moduli space of $\Sigma_g$ for $g>1$ the same number $3g-3$? Is there any deep relation?
Thank you!