Collateral posted in currency XYZ is remunerated at $\text{OIS}_{\text{XYZ}}$, which translates, using the XYZUSD basis, into a synthetic USD rate $\text{OIS}_{\text{USD}}^{\text{XYZ}} = \text{OIS}_{\text{USD}} + \text{basis}_{\text{XYZUSD}}$. If you post collateral you want to choose the currency XYZ that has the highest equivalent synthetic USD rate, and that's your CTD.
Now assume that any future point in time $t$ you can switch from one currency to another. The optimal choice will depend on all the XYZUSD basis observed at that time. Hence you get optionality from the basis being stochastic, hence the dependency of CTD to basis volatility.
To build the CTD curve you first compute all the XYZUSD forward basis curves. If you disregard basis volatility than future basis is today's forward basis, and thus you build your CTD curve discount factors as
$$
D_{\text{USD}}^{\text{CTD}}(T)=D_{\text{OIS}_{\text{USD}}}(T) \exp\left(-\int_0^T\max_{\text{XYZ}}\{\text{basis}_{\text{XYZUSD}}(t)\} dt \right)
$$
That's the methodology used by many, if not most, desks. To take volatility into account you need to model the basis as being stochastic (using for instance an Ornstein Uhlenbeck process for each basis in the spirit of the Hull & White interest rate model) and compute the CTD curve discount factors as
$$
D_{\text{USD}}^{\text{CTD}}(T)=D_{\text{OIS}_{\text{USD}}}(T) \mathbb{E}\left[\exp\left(-\int_0^T\max_{\text{XYZ}}\{\text{basis}_{\text{XYZUSD}}(t)\} dt \right)\right]
$$
using some kind of numerical method such as Monte Carlo simulation.
A side note: $\text{basis}_{\text{XYZUSD}}$ is the spread on a OIS vs. OIS cross currency swaps. But these are not quoted, only Libor vs. Libor cross currency swaps are quoted. To obtain the OIS vs. OIS basis you need to adjust the Libor vs. Libor basis by the OIS-Libor basis in each currency. In practice this means that you bootstrap all your OIS & Libor curves, and then you bootstrap the forward $\text{basis}_{\text{XYZUSD}}$ basis curves.