Let $Q_1$ and $Q_2$ two different objects in the Universe (we can think to two galaxies or quasars), that we observe from the Earth at different angular position $(\alpha_1,\delta_1)$, $(\alpha_2,\delta_2)$ and at different redshift $z_1$,$z_2$.
I know how to find the distances of the two objects from the Earth at the present epoch ( the comoving distance): $$ d_C(Q_i)=\dfrac{c}{H_0}\int_0^{z_i}\dfrac {dz}{E(z)} $$
Now I want to find the comoving distance (at epoch $z=0$) between the two objects.
My first idea is to use the classical formulas for the transformation of spherical to cartesian coordinates and find the cartesian coordinates of the two objects, than calculate the Pythagorean distance. But this can work only in a flat space, so it seems not useful in general.
My final goal is to find the distances between the two objects at any epoch and the relative redshift of one of them observed by the other.
Searching on the books that I have and on Internet I don't find a general solution of this problem. Someone know the solution or has some reference?