Take the two lines horizontally. Each point forms pair with "left" or "right" (of the same line) point of the same line or point of another line. Once the pairing of "same line" are determined, "another line" pairing determined uniquely. Therefore, there are at most three choices for each point. Especially for end-point(left-most or right-most) points at each line, there are at most two choices.
If all of 40 points lies on a line, there are at most $2^{38}\times 1^2<3^{39}$ ways (another-line choice is prohibited).
If only one of 40 points lies on a line, there are at most $3^{37}\times 2^2\times 1<3^{39}$ ways.
For another case, there are at most $3^36\times 2^4<3^{39}$ ways. DONE.