Let $x_0$ be the intersection point of two lines $g$ and $h$, given by
\begin{align*}
g(t)=x_0+tv,\qquad h(t)=x_0+tw,
\end{align*}
where $v$ is a vector pointing along $g$ and $w$ is a vector pointing along $h$. Then the points which have the same distance to $g$ and $h$ lie on the lines given by
\begin{align*}
x_0+t\left(\frac{v}{|v|}\pm\frac{w}{|w|}\right).
\end{align*}
One simplification is to set
\begin{align}
a &= \text{xPos}_2 - \text{xPos}_1, \\
b &= \text{xVel}_2 - \text{xVel}_1, \\
c &= \text{yPos}_2 - \text{yPos}_1, \\
d &= \text{yVel}_2 - \text{yVel}_1.
\end{align}
The vector of displacement from object $1$ to object $2$ at time $t$
is $(a + bt, c + dt)$, and the distance is
$\sqrt{(a + bt)^2 + (c + dt)^2}$.
Your function $f(t)$ becomes
$$
f(t) = (a + bt)^2 + (c + dt)^2 = (b^2 + d^2)t^2 + 2(ab + cd)t + (a^2 + c^2).
$$
In effect, what this does is to convert all your coordinates to the frame of
reference of one of the two objects.
The object whose frame of reference you choose is always at the point
$(0,0)$ in that frame of reference, so all you have to track is the
relative position of the second object, which travels along a straight
line at constant speed.
Now it should be clear that $f(t)$ is the quadratic function
$$ f(t) = At^2 + Bt + C \tag1$$
where $A = b^2 + d^2$, $B = 2(ab + cd)$, and $C = a^2 + c^2$.
In the exceptional case where $b=d=0$, there is no relative motion,
and $f(t)$ remains a constant $a^2 + c^2$. In any other case,
you can find the exact minimum using derivatives, or simply recall
the formula for the vertex of a parabola in this form, which tells us
that the minimum occurs at
$$
t_{\min} = -\frac{B}{2A} = -\frac{ab + cd}{b^2 + d^2}.
$$
If you plug in known values of $\text{xPos}_1$, $\text{xPos}_2$, etc.,
this gives an exact solution for $t_{\min}$, which
you can plug into equation $(1)$ to get the minimum distance
without any guesswork or approximation.
Note that if you replaced $b_x$, $d_x$, $b_y$, and $d_y$
in your version of $f(t)$ with their equal multiples of $t$
(that is, do not replace expressions such as $t \cdot \text{xVel}_1$
with something "simpler"),
expanded all the products, and combined terms with the same powers of $t$,
you would eventually reduce $f(t)$ to something in the form
$ f(t) = At^2 + Bt + C$ where $A$, $B$, and $C$ came out to the same
values in terms of $\text{xPos}_1$, $\text{xPos}_2$, etc.,
as in the calculations above. It would just take more
manipulation do to so.
Best Answer
What you need is the cosine rule . $\cos p = \frac{a^2+b^2-c^2}{2ab}$, where b is the side opposite to the angle p. Which gives you, $c = \sqrt{x^2+y^2-2xy\cos 20}$ = "distance" between the two lines for your case. Here, x and y are the distances along the two lines. For further help with the cosine rule: https://en.wikipedia.org/wiki/Law_of_cosines