Given that I want to calculate the distance of a vector x (say from the blue distribution) from the centroid of a different distributions than x's - say centroid of the red vectors:
I want to use the Mahalanobis distance:
$M^2 = (x-\mu)^T \Sigma^{-1}(x-\mu)$
Is the covariance matrix $\Sigma^{-1}$ than calculated only from the distribution of the here red vectors? If so, how is the distribution of the blue datapoints considered?

It depends on what your model for this data is. Judging from the image you provided, a Gaussian Mixture Model is applied, that is we have
$$x\mid A \sim \mathcal N(\mu_A, \Sigma_A) \qquad x\mid B\sim\mathcal N(\mu_b, \Sigma_B)$$
and in total $p(x) = p(x\mid A)p(A) + p(x\mid B)p(B)$. One commonly writes $\pi_A$ and $\pi_B$ for $p(A)$ and $p(B)$. You can now either